﻿#include "stdafx.h"
#include "UIScriptBinder.h"
#include "UISystem.h"
#include "DebugAssert.h"

_NAMESPACE_BEGIN

/// 脚本使用的新建WidgetWindow对象函数，有参数
static WidgetWindow* New_WidgetWindow(CONST_REF(string) name)
{
	return new WidgetWindow(name);
}

/// 脚本使用的新建WidgetWindow对象函数，无参数
static WidgetWindow* New_EmptyWindow()
{
	return new WidgetWindow;
}

/// 脚本使用的新建WidgetButton对象函数
static WidgetButton* New_WidgetButton(CONST_REF(string) text ,CONST_REF(string) name)
{
	return new WidgetButton(text,name);
}

UI_Binder::UI_Binder()
{
	asIScriptEngine* engine=AngelScriptBinder::Instance()->GetEngine();
	int r;

	///WidgetWindow
	r = engine->RegisterObjectType("WidgetWindow",sizeof(WidgetWindow), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetWindow)
	TYPEMETHODS(WidgetWindow)
	r=engine->RegisterGlobalFunction("WidgetWindow@ New_WidgetWindow(const string&in)",
		asFUNCTION(New_WidgetWindow),asCALL_CDECL);assert( r >= 0 );
	
	r=engine->RegisterGlobalFunction("WidgetWindow@ New_EmptyWindow()",
		asFUNCTION(New_EmptyWindow),asCALL_CDECL);assert( r >= 0 );

	///WidgetButton
	r = engine->RegisterObjectType("WidgetButton",sizeof(WidgetButton), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetButton)
	TYPEMETHODS(WidgetButton)
	DECLARE_DERIVE(WidgetButton,WidgetWindow)
	r=engine->RegisterGlobalFunction("WidgetButton@ New_WidgetButton(const string&in,const string&in)",
		asFUNCTION(New_WidgetButton),asCALL_CDECL);assert( r >= 0 );

	///WidgetListBox
	r = engine->RegisterObjectType("WidgetListBox",sizeof(WidgetListBox), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetListBox)
	TYPEMETHODS(WidgetListBox)
	DECLARE_DERIVE(WidgetListBox,WidgetWindow)

	///WidgetComboBox
	r = engine->RegisterObjectType("WidgetComboBox",sizeof(WidgetComboBox), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetComboBox)
	TYPEMETHODS(WidgetComboBox)
	DECLARE_DERIVE(WidgetComboBox,WidgetWindow)

	///WidgetEditBox
	r = engine->RegisterObjectType("WidgetEditBox",sizeof(WidgetEditBox), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetEditBox)
	TYPEMETHODS(WidgetEditBox)
	DECLARE_DERIVE(WidgetEditBox,WidgetWindow)

	///WidgetRadioButton
	r = engine->RegisterObjectType("WidgetRadioButton",sizeof(WidgetRadioButton), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetRadioButton)
	TYPEMETHODS(WidgetRadioButton)
	DECLARE_DERIVE(WidgetRadioButton,WidgetWindow)

	///WidgetMultilineList
	r = engine->RegisterObjectType("WidgetMultilineList",sizeof(WidgetMultilineList), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(WidgetMultilineList)
	TYPEMETHODS(WidgetMultilineList)
	DECLARE_DERIVE(WidgetMultilineList,WidgetWindow)

	///UiSystem
	r = engine->RegisterObjectType("UiSystem",sizeof(UiSystem), asOBJ_REF|asOBJ_NOHANDLE );	assert( r >= 0 );
	TYPEMETHODS(UiSystem)
	r = engine->RegisterGlobalProperty("UiSystem UiSystem_I",UiSystem::Instance() );	 assert( r >= 0 );
}

_NAMESPACE_END

